﻿using UnityEngine;
using System.Collections;

public class CameraController : MonoBehaviour {
	//DEPRECATED
	public float camHeight = 6f;
	public float camSpeed = 2f;
	GameObject[] tiles;
	GameObject current;

	// Use this for initialization
	void Start () {
		tiles = GameObject.FindGameObjectsWithTag("Tile");
	}

	// Update is called once per frame
	void Update () {
		Debug.Log("Tiles: "+tiles.Length);
		MoveCamera();
	}

	void MoveCamera(){
		foreach(GameObject tile in tiles){
			if(tile.GetComponentInChildren<CameraTrigger>().active){
				current = tile;
				Debug.Log("Tile on "+current.transform.position.x+"|"+current.transform.position.y+"|"+current.transform.position.z+" is active");
				Vector3 nextPos = new Vector3(current.transform.position.x,camHeight,current.transform.position.z);
				transform.position = Vector3.Lerp(transform.position,nextPos,Time.deltaTime*camSpeed);
				Debug.Log("Moving Cam to "+nextPos.x+"|"+nextPos.y+"|"+nextPos.z);
			}
			else{
				Debug.Log("No Tile Active");
				current = null;
			}
		}
	}
}
